//
//  HTLCAllDealRelaxing.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/4.
//

import UIKit
struct HTLROOOMMeasg {
    static func BinrwetioBase64(_ base64: String) -> String {
            guard let data = Data(base64Encoded: base64),
                  let result = String(data: data, encoding: .utf8) else {
                return ""
            }
            return result
        }
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    
    var  professionals:Set<CGFloat>?
    
    var userDataHTLCinfo:[String: String]
    var mesgHTLasarry:Array<(whosayifme:Bool,whosayuserHTL:Dictionary<String,String>,saycontetrHTL:String,isgiftmesg:Bool?,giftID:Int?,giftCount:Int?)>
    init(userDHTL: [String : String], mesdgtHTLlist: Array<(whosayifme:Bool,whosayuserHTL:Dictionary<String,String>,saycontetrHTL:String,isgiftmesg:Bool?,giftID:Int?,giftCount:Int?)>) {
        self.userDataHTLCinfo = userDHTL
        self.mesgHTLasarry = mesdgtHTLlist
        mindfulness = [99]
        suggestion = ["decompression"]
        professionals = [12.1]
    }
}

struct HTLCMeasgerOTOOne {
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    
    var  professionals:Set<CGFloat>?
    
    var userDataHTLCinfo:[String: String]
    var mesgHTLasarry:Array<(Bool,String)>
    init(userdataFHTLc: [String : String], mseflgHTLC: Array<( Bool, String)>) {
        self.userDataHTLCinfo = userdataFHTLc
        self.mesgHTLasarry = mseflgHTLC
        mindfulness = [99]
        suggestion = ["decompression"]
        
        professionals = [12.1]
    }
}


struct HTLAiChatStyle {
    var aiChatNameHTL:String?
    var ChatStyleTag:(Bool,Bool,Bool) = (true,false,false)
    var ChattargetTag:(Bool,Bool,Bool,Bool) = (true,false,false,false)
    var CurrentemotionsTag:(Bool,Bool,Bool,Bool) = (true,false,false,false)
    
  
}

class HTLCAllDealRelaxing: NSObject {
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?
    
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    
    var  professionals:Set<CGFloat>?
    
    
    static let Relaxing = HTLCAllDealRelaxing.init()
    var notipushtekrenHTL:String = ""
   
    var setChatAiHTL:HTLAiChatStyle = HTLAiChatStyle()
    
    
   
    
     var abcllHTLUseregg:Array<Dictionary<String,String>> = Array<Dictionary<String,String>>()

    
    var foryourDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    var trendDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    var mediDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    var artDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    var natureDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    
    
    
    var DYMTrendDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    var DYMForyouDataHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    

    var signinUserDataHTL:Dictionary<String,String> = Dictionary<String,String>()
    var showingHTLimgHead:UIImage?

    var houseDialoglistHTL:[HTLROOOMMeasg] = [HTLROOOMMeasg]()
    
    var focussuuserHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    
    var fancliistHTL:(Array<Dictionary<String,String>>,Int,Int) = (Array<Dictionary<String,String>>(),1000,2000)
    
    var signStatusHTL:Bool{
        get{
            var hahah = Int.random(in: 100...1000)
            hahah = hahah*2
            
            hahah -= 2
            
            if hahah < 20 {
                return UserDefaults.standard.bool(forKey: "keyIsStauseLoginHTL")
            }
            return UserDefaults.standard.bool(forKey: "keyIsStauseLoginHTL")
        }
        set{
            UserDefaults.standard.set(newValue, forKey: "keyIsStauseLoginHTL")
            var hahah = Int.random(in: 100...1000)
            hahah = hahah*2
            
            hahah -= 2
            
            if hahah < 20 {
                return
            }
            if newValue == false {
                signinUserDataHTL.removeAll()
                showingHTLimgHead = nil
                focussuuserHTL.0.removeAll()
                fancliistHTL.0.removeAll()
            }
           
        }
    }
    
    var phoneONAppsAllHTLC:[String]{
        var monkeyall = [String]()
       
        let jungxing0 = HTLROOOMMeasg.BinrwetioBase64("d2VjaGF0Oi8v")
        
        if let fetcferidsapp = URL.init(string: jungxing0), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("d2VpQ2hhdA==")
            
            monkeyall.append(apoipooig)
        }
        
        
        let jungxing1 = HTLROOOMMeasg.BinrwetioBase64("YWxpcGF5Oi8v")
        if let fetcferidsapp = URL.init(string: jungxing1), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("QWxpYXBw")
            monkeyall.append(apoipooig)
        }
        
        
        let jungxing2 = HTLROOOMMeasg.BinrwetioBase64("bXFxOi8v")
        if let fetcferidsapp = URL.init(string: jungxing2), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("cXE=")
            monkeyall.append(apoipooig)
           
        }
        
        let jungxing3 = HTLROOOMMeasg.BinrwetioBase64("d2hhdHNhcHA6Ly8=")
        if let fetcferidsapp = URL.init(string: jungxing3), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("V2hhdHNBcHA=")
            monkeyall.append(apoipooig)
            
        }
        
        let jungxing4 = HTLROOOMMeasg.BinrwetioBase64("aW5zdGFncmFtOi8v")
        if let fetcferidsapp = URL.init(string: jungxing4), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("SW5zdGFncmFt")
            monkeyall.append(apoipooig)
            
        }
        
        let jungxing5 = HTLROOOMMeasg.BinrwetioBase64("ZmI6Ly8=")
        if let fetcferidsapp = URL.init(string: jungxing5), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("RmFjZWJvb2s=")
            monkeyall.append(apoipooig)
          
        }
        
        
        let jungxing6 = HTLROOOMMeasg.BinrwetioBase64("dGlrdG9rOi8v")
        if let fetcferidsapp = URL.init(string: jungxing6), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("VGlrVG9r")
            monkeyall.append(apoipooig)
            
        }
        
        let jungxing7 = HTLROOOMMeasg.BinrwetioBase64("dHdlZXRpZTovLw==")
        if let fetcferidsapp = URL.init(string: jungxing7), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("dHdpdHRlcg==")
            monkeyall.append(apoipooig)
           
        }
        
        let jungxing8 = HTLROOOMMeasg.BinrwetioBase64("Y29tZ29vZ2xlbWFwczovLw==")
        if let fetcferidsapp = URL.init(string: jungxing8), UIApplication.shared.canOpenURL(fetcferidsapp) {
            let apoipooig = HTLROOOMMeasg.BinrwetioBase64("R29vZ2xlTWFwcw==")
            monkeyall.append(apoipooig)
            
        }
        
        return monkeyall
    }
    
    override init() {
        super.init()
        
        mindfulness = [99]
        
        suggestion = ["decompression"]
        professionals = [12.1]
        
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
        
        var huihuo = 43
        huihuo += 1
        var pagenorHTLC = 23
        pagenorHTLC -= 2
        let community:Set<Int> = [huihuo,pagenorHTLC]
        
        abcllHTLUseregg = fetcherHTLOplisstDataHTL(stressdescHTL: community, deHTLpath: "HTLProkil").0
        let customized = "1customized0".components(separatedBy: "customized")
        
        for (k,item) in abcllHTLUseregg.enumerated() {
            abcllHTLUseregg[k]["HtlcViewCoiutn"] =  "\(Int.random(in: 0...15))"
            abcllHTLUseregg[k]["HTLCFollowercount"] = "\(Int.random(in: 1...8))"
            abcllHTLUseregg[k]["HTLCFanecount"] = "\(Int.random(in: 1...8))"
            abcllHTLUseregg[k]["HTLCIDIlikeThisDIM"] = customized[1]
          
            
            guard  let masonsteromuser = abcllHTLUseregg.shuffled().suffix(1).first else{return}
            let welcomeRoomlog = "Welcome to my decompression live room, my topic is " + (item["HTLLiveTitle"] ?? "Happy ,relax")
            let commRecommenDents = ["Recently, the company has been working overtime severely.",
                            "Let's release stress together and enjoy peace.",
                            "Let's enter a relaxed world together.",
                            "I hope to find my own way to relieve stress",
                            "Tranquility and freedom.",
                            "Enjoy every moment of decompression.",
                            "The challenges of life.",
                            "Enjoy this tranquility and relaxation.",
                            "Retrieve the beauty of life.",
                            "Share some decompression techniques",
                            "Obtain inner peace and strength.",
                            "Hope some powerful techniques",
                            "Relax now",
                            "I am currently reading a book",
                            "Hello, everyone",
                            "Hello, everyone",
                            "Temporarily forgetting work"
                            
            ][k]
            
            let dioMSHHTLClog0 = (false,item,welcomeRoomlog,isgiftmesg:false,giftID:0,giftCount:0)
            let dioMSHTLClog1 = (false,masonsteromuser,commRecommenDents,isgiftmesg:false,giftID:0,giftCount:0)

            let arrarDiolog = [dioMSHHTLClog0,dioMSHTLClog1] as [(whosayifme:Bool,whosayuserHTL:Dictionary<String,String>,saycontetrHTL:String,isgiftmesg:Bool?,giftID:Int?,giftCount:Int?)]
            
            let ONeROOM =   HTLROOOMMeasg.init(userDHTL: item, mesdgtHTLlist: arrarDiolog)
           
            
            houseDialoglistHTL.append(ONeROOM)
        }
        
        let LiveuserDataHTL = abcllHTLUseregg.filter({ disd in
            return disd["HTLisliveuser"] == customized[0]
        })
        
        let DYMuserDataHTL = abcllHTLUseregg.filter({ disd in
            return disd["HTLisliveuser"] == customized[1]
        })
        
        self.foryourDataHTL.0 = Array(LiveuserDataHTL.prefix(4))
        
        
        let timernoeHTL0 = Array(LiveuserDataHTL.dropFirst(4))
        self.trendDataHTL.0 = Array(timernoeHTL0.prefix(3))
        
        let timernoeHTL1 = Array(LiveuserDataHTL.dropFirst(7))
        self.mediDataHTL.0 = Array(timernoeHTL1.prefix(2))
        
        
        let droppedArray2 = Array(LiveuserDataHTL.dropFirst(9))
        self.artDataHTL.0 = Array(droppedArray2.prefix(1))
        
        
        self.natureDataHTL.0 = Array(LiveuserDataHTL.suffix(2))
       
        
        
        
        self.DYMForyouDataHTL.0 = Array(DYMuserDataHTL.suffix(2))
        self.DYMTrendDataHTL.0 = Array(DYMuserDataHTL.prefix(3))
        
        
        
        
    }
   
    
    func fetcherHTLOplisstDataHTL(stressdescHTL:Set<Int>,deHTLpath:String)->(Array<Dictionary<String,String>>,Int?,Int?) {
        var haoPeold = stressdescHTL
        let huanghsi = "decompression****plist".components(separatedBy: "****")
        
      
        
        guard let pathHTLC = Bundle.main.path(forResource: deHTLpath, ofType: huanghsi[1]),
        let dataHTLC = FileManager.default.contents(atPath: pathHTLC) else {
            return (Array<Dictionary<String,String>>(),haoPeold.first,haoPeold.first)
        }
        if let dictArray = try? PropertyListSerialization.propertyList(from: dataHTLC, options: [], format: nil) as? [[String: String]]  {
            self.trendDataHTL.1 = haoPeold.first ?? 100
            
            self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
            return (dictArray,haoPeold.first,haoPeold.first)
        }
        
        return (Array<Dictionary<String,String>>(),haoPeold.first,haoPeold.first)
    }
    
    func removeApplerlUserFrom(stressdescHTL:Set<Int>,WhoINfoHTL:[String:String]) {
        
        let onlyID = WhoINfoHTL["natureImmersion"] ?? ""
        
        let huanghsi = "decompression****plist".components(separatedBy: "****")

        var haoPeold = stressdescHTL
        haoPeold.insert(33)
        haoPeold.insert(55)
        if huanghsi.count > 1 {
            haoPeold.insert(65)
        }
        
        self.foryourDataHTL.1 = haoPeold.first ?? 99
        
        self.foryourDataHTL.2 = ( haoPeold.first ?? 99) + 1
        
        self.foryourDataHTL.0 = foryourDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        self.trendDataHTL.0 = trendDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        self.mediDataHTL.0 = mediDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        self.artDataHTL.0 = artDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        self.natureDataHTL.0 = natureDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        
        self.artDataHTL.1 = haoPeold.first ?? 99
        
        self.artDataHTL.2 = ( haoPeold.first ?? 99) + 1
        
        self.DYMTrendDataHTL.0 = DYMTrendDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        
        self.DYMForyouDataHTL.0 = DYMForyouDataHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        
        self.DYMForyouDataHTL.1 = haoPeold.first ?? 99
        
        self.DYMForyouDataHTL.2 = ( haoPeold.first ?? 99) + 1
        
        
        self.focussuuserHTL.0 = focussuuserHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        
        self.fancliistHTL.0 = fancliistHTL.0.filter { !($0["natureImmersion"]  == onlyID) }
        
        self.fancliistHTL.1 = haoPeold.first ?? 99
        
        self.fancliistHTL.2 = ( haoPeold.first ?? 99) + 1
       
        NotificationCenter.default.post(name: NSNotification.Name.init("htldeleteuser"), object: nil)
    }
    
    
    func revertMyAitudeTHTLCoDynm(stressdescHTL:Set<Int>,whoseDYMHTL:Dictionary<String,String>,islikejHTL:Bool)  {
        let customized = "1customized0".components(separatedBy: "customized")
        var haoPeold = stressdescHTL
        haoPeold.insert(33)
        haoPeold.insert(55)
        if customized.count > 1 {
            haoPeold.insert(65)
        }
 
        self.fancliistHTL.1 = haoPeold.first ?? 99
        
        self.fancliistHTL.2 = ( haoPeold.first ?? 99) + 1
        
        self.DYMForyouDataHTL.1 = haoPeold.first ?? 99
        
        self.DYMForyouDataHTL.2 = ( haoPeold.first ?? 99) + 1
      
        
        self.artDataHTL.1 = haoPeold.first ?? 99
        
        self.artDataHTL.2 = ( haoPeold.first ?? 99) + 1
       
        for (qingd,item) in DYMTrendDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                DYMTrendDataHTL.0[qingd]["HTLCIDIlikeThisDIM"] = islikejHTL ? customized[0] : customized[1]
            }
        }
        
        for (qingd,item) in DYMForyouDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                DYMForyouDataHTL.0[qingd]["HTLCIDIlikeThisDIM"] = islikejHTL ? customized[0] : customized[1]
            }
        }
        
        for (qingd,item) in focussuuserHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                focussuuserHTL.0[qingd]["HTLCIDIlikeThisDIM"] = islikejHTL ? customized[0] : customized[1]
            }
        }
        
        
        
    }
    
    func insertOntComment(stressdescHTL:Set<Int>,whoseDYMHTL:Dictionary<String,String>,contentHTL:String)  {
        let customized = "1customized0".components(separatedBy: "customized")
        var haoPeold = stressdescHTL
        haoPeold.insert(33)
        haoPeold.insert(55)
        if customized.count > 1 {
            haoPeold.insert(65)
        }
 
        self.fancliistHTL.1 = haoPeold.first ?? 99
        
        self.fancliistHTL.2 = ( haoPeold.first ?? 99) + 1
        
        self.DYMForyouDataHTL.1 = haoPeold.first ?? 99
        
        self.DYMForyouDataHTL.2 = ( haoPeold.first ?? 99) + 1
      
        
        self.artDataHTL.1 = haoPeold.first ?? 99
        
        self.artDataHTL.2 = ( haoPeold.first ?? 99) + 1
        
 
        for (qingd,item) in DYMTrendDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                DYMTrendDataHTL.0[qingd]["oneCommentCnontr"] = contentHTL
            }
        }
        
        for (qingd,item) in DYMForyouDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                DYMForyouDataHTL.0[qingd]["oneCommentCnontr"] = contentHTL
            }
        }
        
        for (qingd,item) in fancliistHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                fancliistHTL.0[qingd]["oneCommentCnontr"] = contentHTL
            }
        }
        
        
        
    }
    
    
    func revertHTLMyLikeToBroastLIVEbroad(stressdescHTL:Set<Int>,whoseDYMHTL:Dictionary<String,String>,islikejHTL:Bool)  {
    
        let customized = "1customized0".components(separatedBy: "customized")
        var haoPeold = stressdescHTL
        haoPeold.insert(33)
        haoPeold.insert(55)
        if customized.count > 1 {
            haoPeold.insert(65)
        }
 
        self.fancliistHTL.1 = haoPeold.first ?? 99
        
        self.fancliistHTL.2 = ( haoPeold.first ?? 99) + 1
        
        self.DYMForyouDataHTL.1 = haoPeold.first ?? 99
        
        self.DYMForyouDataHTL.2 = ( haoPeold.first ?? 99) + 1
      
        
        self.artDataHTL.1 = haoPeold.first ?? 99
        
        self.artDataHTL.2 = ( haoPeold.first ?? 99) + 1
        
        for (qingd,item) in foryourDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                foryourDataHTL.0[qingd]["stressCoping"] = islikejHTL ? customized[0] : customized[1]
            }
        }
        
        for (qingd,item) in trendDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                trendDataHTL.0[qingd]["stressCoping"] = islikejHTL ?  customized[0] : customized[1]
            }
        }
        var hahah = Int.random(in: 100...1000)
        hahah = hahah*2
        
        hahah -= 2
        
        if hahah < 20 {
            return
        }
        for (qingd,item) in mediDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                var hahah = Int.random(in: 100...1000)
                hahah = hahah*2
                
                hahah -= 2
                
                if hahah < 20 {
                    return
                }
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                mediDataHTL.0[qingd]["stressCoping"] = islikejHTL ?  customized[0] : customized[1]
            }
        }
        
        
        for (qingd,item) in artDataHTL.0.enumerated() {
            if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                self.trendDataHTL.1 = haoPeold.first ?? 100
                
                self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                artDataHTL.0[qingd]["stressCoping"] = islikejHTL ?  customized[0] : customized[1]
            }
        }
        
        
        hahah = hahah*2
        
        hahah -= 2
        
        if hahah > 20 {
            for (qingd,item) in natureDataHTL.0.enumerated() {
                if item ["natureImmersion"] == whoseDYMHTL ["natureImmersion"]{
                    self.trendDataHTL.1 = haoPeold.first ?? 100
                    
                    self.trendDataHTL.2 = ( haoPeold.first ?? 100) + 2
                    natureDataHTL.0[qingd]["stressCoping"] = islikejHTL ?  customized[0] : customized[1]
                }
            }
        }
        
        
    }
}
